﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Text.RegularExpressions;

namespace FxCopContrib.Experimental.RegexCop
{
    public class SingleRange : PrivateReflectionWrapper
    {
        private static readonly Assembly RegexAssembly = typeof(Regex).Assembly;
        private const string SingleRangeTypeFullName = "System.Text.RegularExpressions.RegexCharClass+SingleRange";
        private static readonly Type SingleRangeType = RegexAssembly.GetType(SingleRangeTypeFullName);

        public SingleRange() : base(SingleRangeType){}
        public SingleRange(object internalSingleRange) : base(SingleRangeType, internalSingleRange) { }

        public Char First
        {
            get
            {
                return GetFieldValue<char>("_first");
            }
        }

        public Char Last
        {
            get
            {
                return GetFieldValue<char>("_last");
            }
        }

        public IEnumerable<char> ToEnumerable()
        {
            char last = Last;
            if (Last == char.MaxValue)
            {
                last = First;
            }

            char toReturn = First;
            while (toReturn <= Last)
            {
                yield return toReturn;
                toReturn++;
            }
        }

        public bool Intersects(SingleRange range)
        {
            //TODO: Implement
            return true;
        }
    }
}
